/* 
 * Copyright 2013 Sébastien Mouquet.
 * 
 * This file is part of ECovoiturage.
 * 
 * ECovoiturage is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * ECovoiturage is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with ECovoiturage. If not, see http://www.gnu.org/licenses/.
 */
package com.smouquet.ecovoiturage.ui.page.root.trajetmidi;

import com.smouquet.ecovoiturage.core.bean.TrajetMidiInteresseItem;
import com.vaadin.data.util.BeanItemContainer;
import com.vaadin.ui.Table;
import java.util.List;

/**
 *
 * @author sebastien.mouquet
 */
public class TrajetMidiInteressesTable extends Table
{
    private List<TrajetMidiInteresseItem> interesses;
    
    
    public TrajetMidiInteressesTable() {}
    
    public TrajetMidiInteressesTable(List<TrajetMidiInteresseItem> interesses)
    {
        this.interesses = interesses;
        prepareAndInstallDataSource();
    }

    
    public void setInteresses(List<TrajetMidiInteresseItem> interesses)
    {
        this.interesses = interesses;
        prepareAndInstallDataSource();
    }
    
    
    private void prepareAndInstallDataSource()
    {
        BeanItemContainer<TrajetMidiInteresseItem> container = new BeanItemContainer<TrajetMidiInteresseItem>(TrajetMidiInteresseItem.class);

        for(TrajetMidiInteresseItem t : interesses) {
            container.addItem(t);
        }
        
        setContainerDataSource(container);

        setColumnHeader("nomInteresse", "Interessé");
        setColumnHeader("nbPlaces", "Nb. places proposées");

        setColumnWidth("nbPlaces", 200);
        
        setColumnAlignment("nbPlaces", Align.RIGHT);
        
        setVisibleColumns(new Object[] {"nomInteresse", "nbPlaces"});
    }
}
